<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Mojito管理端</title>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
  <link rel="stylesheet" href="../../styles/common.css">
  <link rel="stylesheet" href="../../styles/login.css">
  <link rel="stylesheet" href="../../styles/icon/iconfont.css"/>
  <style>
    @keyframes opacity {
      0% {
        opacity: 0;
      }
      100% {
        opacity: 1;
      }
    }
    body {
      opacity: 0;
      animation: opacity 0ms ease-out 500ms forwards;
      min-width: 1366px;
    }
  </style>
</head>
<body>
  <div class="login" id="login-app">
    <div class="login-box">
      <img src="../../images/logo/login-l.jpeg" alt="">
      <div class="login-form">
        <el-form ref="loginForm" :model="loginForm" :rules="rules">
          <div class="login-form-title">
            <img src="../../images/logo/login-logo.png" style="width:210px;height:70px;" alt="" />
          </div>
          <el-form-item prop="loginId">
            <el-input v-model.trim="loginForm.loginId" type="text" placeholder="帐号/手机号码"
                      maxlength="20" prefix-icon="iconfont icon-user" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model.trim="loginForm.password" type="password" placeholder="密码" show-password
                      maxlength="20" prefix-icon="iconfont icon-lock" @keyup.enter.native="handleLogin" />
          </el-form-item>
          <el-form-item style="width:100%;">
            <el-button :loading="loading" class="login-btn" size="medium" type="primary" style="width:100%"
                       @click.native.prevent="handleLogin">
              <span v-if="!loading">登录</span>
              <span v-else>登录中...</span>
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="../../plugins/vue/vue.js"></script>
  <!-- 引入组件库 -->
  <script src="../../plugins/element-ui/index.js"></script>
  <!-- 引入axios -->
  <script src="../../plugins/axios/axios.min.js"></script>
  <script src="../../js/request.js"></script>
  <script src="../../js/validate.js"></script>
  <script src="../../api/employee.js"></script>
  <script>
    new Vue({
      el: '#login-app',
      data() {
        return {
          loginForm:{
            loginId: '',
            password: ''
          },
          loading: false
        }
      },
      computed: {
        rules() {
          return {
            loginId: [{required: true, message: '请输入帐号或手机号码', trigger: 'blur'}],
            password: [{required: true, message: '请输入密码', trigger: 'blur'}]
          }
        }
      },
      created() {},
      methods: {
        async handleLogin() {
          this.loading = true
          this.$refs.loginForm.validate(async (valid) => {
            if (valid) {
              loginApi(this.loginForm).then(res => {
                window.location.href= '/backend/index.html'
              }).catch(error => {
                this.$message.error(error.message)
                this.loading = false
              })
            } else{
              this.loading = false
              return false
            }
          })
        }
      }
    })
  </script>
</body>
</html>
